{extend name="public:base"}
{block name='css'}
<style>
    ::-webkit-scrollbar {display:none}
</style>
{/block}

{block name='body'}
<div class="view view-main white-navbar white-toolbar">
    <div data-name="home" class="page">

        <div class="navbar">
            <div class="navbar-inner">
                <div class="left"><a href="javascript:history.back()" class="external"><i class="iconfont icon-fanhui"></i></a></div>
                <div class="center"><span>订单详情</span></div>
                <div class="right"></div>
            </div>
        </div>

        <div class="page-content ">
            <div class="jiesuan">

                <div class="list order-info-t">
                    <ul>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title">订单编号</div>
                                    <div class="item-after">{$info.sn}</div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title">订单状态</div>
                                    <div class="item-after">{$state_list[$info.state]}</div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title">下单时间</div>
                                    <div class="item-after">{$info.create_time}</div>
                                </div>
                            </div>
                        </li>
                        {if $info.state==3}
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title">快递公司</div>
                                    <div class="item-after">{$info.ex_name}</div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title">快递单号</div>
                                    <div class="item-after">{$info.express_code}</div>
                                </div>
                            </div>
                        </li>
                        {/if}
                    </ul>
                </div>

                <div class="adre">
                    <div class="yead">
                        <div class="ico"><i class="iconfont icon-dizhi"></i></div>
                        <div class="z">
                            <p class="p1">{$info.name}&nbsp;&nbsp;&nbsp;&nbsp;{$info.phone}&nbsp;&nbsp;&nbsp;</p>
                            <p class="p2">{$info.address}</p>
                        </div>
                    </div>
                </div>

                <div class="goods">
                    {volist name='info.goods_list' id='goods'}
                    <div class="mt">
                        <img src="{$goods.img}" alt="" />
                        <div class="y">
                            <p class="p1">{$goods.title}</p>
                            <!-- <p class="p3">{$goods.spec}</p> -->
                            <p class="p2"><span>￥{$goods.price}</span>x {$goods.num|floatval=###}</p>
                        </div>
                    </div>
                    {/volist}
                </div>
                <div class="list inline-labels no-hairlines-md" style="margin:0px;">
                    <ul>
                        <li class="item-content item-input">
                            <div class="item-inner">
                                <div class="item-title item-label" style="width:70px;">备注</div>
                                <div class="item-input-wrap o-note">{$info.remark}</div>
                            </div>
                        </li>
                    </ul>
                </div>

                
                <div class="jie">
                    
                </div>
                
                <div class="jie">

                    <p class="p2" style="margin:0px;">
                        <span class="sp2 y" style="color:#ff4242;font-size:16px;">￥{$info.total_amount}</span>
                        <span class="sp1 y">金额：</span>
                    </p>
					<p class="p2" style="margin:0px;">
                        <span class="sp2 y" style="color:#ff4242;font-size:16px;">{:get_pay_way($info.pay_way)}</span>
                        <span class="sp1 y">支付方式：</span>
                    </p>
					
                </div>

            </div>

            <div class="block">
                {switch name='info.state'}
                {case value='1'}
                <p class="row segmented-round">
                    <button onclick="toPay();" class="col button button-big button-fill " style="background:#66ba61;">支付</button>
                </p>
                <p class="row segmented-round">
                    <button onclick="orderClose();" class="col button button-big button-fill" style="background:#ffb759;">关闭订单</button>
                </p>
                {/case}
                {case value='3'}
                <p class="row segmented-round">
                    <button onclick="confirmOrder();" class="col button button-big button-fill" style="background:#66ba61;color:#fff;border:1px solid #ededed;">确认收货</button>
                </p>
                {/case}
                {case value='4'}
                <p class="row segmented-round">
                    <!-- <button onclick="window.location.href='{:url('evaluate', ['id'=>$info['id']])}'" class="col button button-big button-fill" style="background:#ffffff;color:#333;border:1px solid #ededed;">去评价</button> -->
                </p>
                {/case}
                {/switch}
            </div>

        </div>


    </div>
</div>
{/block}

{block name="js"}
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript">
    function jsApiCall(params) {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',
            params,
            function(res){
                WeixinJSBridge.log(res.err_msg);
                if(res.err_msg == 'get_brand_wcpay_request:ok'){
                   messageToast('支付成功');
                   setTimeout(function(){
                       window.location.reload();
                   },1000);
                } else {
                    messageToast('调起支付失败');
                }
            }
        );
    }

    function callpay(params)
    {
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall(params);
        }
    }

    function test_pay() {
        $.post( "{:url('pay/test_pay')}" , 'type=order&orderno={$info.orderno}&id={$info.id}', function ( data ) {
            if (/SUCCESS/.test(data)) {
                messageToast('支付成功');
                setTimeout(function(){
                    window.location.reload();
                },1000);
            } else {
                messageToast('支付失败');
            }
        });
    }

    function toPay() {
        $.post( "{:url('pay')}" , 'id={$info.id}', function ( data ) {
            if (data.status == 'y') {
                callpay(JSON.parse(data.data));
            } else {
                messageToast(data.info);
            }
        }, "json");
    }
    //关闭订单
    function orderClose(){
        app.dialog.confirm('确定要关闭订单吗？', function () {
            $.post( "{:url('state')}" , 'id={$info.id}&status=9', function ( data ) {
                messageToast(data.info);
                if (data.status == 'y') {
                    setTimeout(function () {
                        self.location = "{:url('index')}";
                    }, 1000);
                }
            }, "json");
        });
    }
    //关闭订单
    function confirmOrder(){
        app.dialog.confirm('确定已经收到货了吗？', function () {
            $.post( "{:url('state')}" , 'id={$info.id}&status=4', function ( data ) {
                messageToast(data.info);
                if (data.status == 'y') {
                    setTimeout(function () {
                        self.location = window.location.href;
                    }, 1000);
                }
            }, "json");
        });
    }
</script>
{/block}